home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / www / amitrix / as.lha / AutoSearch / AutoSearch.awebrx next >
Text File  |  1998-02-21  |  5KB  |  208 lines

  1. /*
  2.     $VER: AutoSearch 2.4 (21.2.98) by Gabriele Favrin (favrin@tin.it)
  3. */
  4.  
  5. options results
  6. parse ARG args
  7. parse SOURCE . . called .
  8.  
  9. domain = ".com"
  10. cfg     = findpath(called)||"autosearch.cfg"
  11. multi     = 1
  12. eol     = '0A'x
  13. servercfg = ""
  14. server = 1
  15.  
  16. s.1.url="http://altavista.digital.com/cgi-bin/query?pg=q&q="
  17. s.1.name="AltaVista"
  18. s.2.url="http://www-english.lycos.com/cgi-bin/pursuit?cat=lycos&mtemp=lite&terse=&query="
  19. s.2.name="Lycos"
  20. s.3.url="http://search.yahoo.com/bin/search?p="
  21. s.3.name="Yahoo"
  22. s.4.url="http://www.excite.com/search.gw?search="
  23. s.4.name="Excite"
  24. s.5.url="http://www.nlsearch.com/nlquery.fcg?sb=Search&si=&us=025&cc=&qr="
  25. s.5.name="Northern Light"
  26.  
  27. If (args == "") | (args == "%3F") then do
  28.     If Exists(cfg) then do
  29.         Call LoadCFG()
  30.     end
  31.     else do
  32.         s.1.use=1
  33.     end
  34.  
  35.     Call CreateHTMLCFG()
  36.     Call SendToAWeb('T:autosearchCFG.html')
  37. end
  38. else do
  39.     If Left(args, 1) == "." then do
  40.         Call ParseACFG()
  41.         Call SaveCFG()
  42.     end
  43.     else do
  44.         If Exists(cfg) then do
  45.             Call LoadCFG()
  46.         End
  47.         else do
  48.             s.1.use=1
  49.         End
  50.  
  51.         If Left(args, 1) == "@" then do
  52.             url='http://www.'Right(args, Length(args)-1)||domain
  53.             'UrlField SET' url
  54.             'Open "'url'"'
  55.         end
  56.         else do
  57.             Call DoSearch()
  58.         end
  59.     end
  60. end
  61.  
  62. exit 0
  63.  
  64.  
  65. ParseACFG:
  66.     fp=Pos(' ', args)-1
  67.     interpret SubStr(args, 2, fp)
  68.  
  69.     sp=Pos('server', args)
  70.     If sp ~= 0 then do
  71.         multi=0
  72.         do while (sp ~= 0)
  73.             interpret SubStr(args, sp, 11)
  74.             s.server.use=1
  75.             servercfg=servercfg||server||eol
  76.             multi=multi+1
  77.  
  78.             sp=Pos('server', args, sp+10)
  79.         end
  80.     end
  81.     else do
  82.         interpret Right(args, Length(args)-1)
  83.         multi=1
  84.         servercfg="1"||eol
  85.     end
  86.     return
  87.  
  88.  
  89. CreateHTMLCFG:
  90.     ct=1
  91.  
  92.     html='<html><head><title>AutoSearch configuration page</title></head><body><table border align=center><tr valign=top align=center><td><form name="config" action="x-aweb:rexx/'called'">Domain for default name completion<br><input size=6 name=".domain" value="'domain'"><br>(eg. <code>.com , .it , .nl</code>)<td>Search Engines:<br><select name="server" multiple>'
  93.     do while s.ct.name ~== "S."ct".NAME"
  94.         html=html||'<option value="'ct'"'
  95.         If (s.ct.use == 1) then do
  96.             html=html||' selected>'s.ct.name' '
  97.         end
  98.         else do
  99.             html=html||'>'s.ct.name' '
  100.         end
  101.         ct=ct+1
  102.     end
  103.     html=html||'</select><tr><td colspan=2 align=center><input type="submit" value="Save Configuration"></form></table></body></html>'
  104.     return
  105.  
  106.  
  107. SendToAWeb:
  108.     parse ARG file
  109.  
  110.     If Open(fp, file, 'W') then do
  111.         Call WriteLN(fp, html)
  112.         Call Close(fp)
  113.  
  114.         'AllowCMD'
  115.         'Open file:///'file' RELOAD'
  116.         'Wait file:///'file
  117.         'UrlField SET "AutoSearch 2.4"'
  118.         address command 'Delete >NIL: QUIET "'file'"'
  119.     end
  120.     else do
  121.         'Request "AutoSearch" "Can''t create temporary file." "_Ok" NOWAIT'
  122.     end
  123.     return
  124.  
  125.  
  126. LoadCFG:
  127.     If Open(fp, cfg, 'R') then do
  128.         domain=ReadLN(fp)
  129.         multi=ReadLN(fp)
  130.  
  131.         do ct=1 to multi
  132.             server=ReadLN(fp)
  133.             s.server.use=1
  134.         end
  135.         Call Close(fp)
  136.     end
  137.     else do
  138.         'Request "AutoSearch" "Can''t read configuration" "_Ok" NOWAIT'
  139.     end
  140.     return
  141.  
  142.  
  143. SaveCFG:
  144.     If Open(fp, cfg, 'W') then do
  145.         Call WriteCH(fp, domain||eol||multi||eol||servercfg)
  146.     end
  147.     else do
  148.         'Request "AutoSearch" "Can''t save configuration" "_Ok" NOWAIT'
  149.     end
  150.     return
  151.  
  152.  
  153. DoSearch:
  154.     searchtext=args
  155.  
  156.     If (multi == 1) then do
  157.         'Open "'s.server.url||searchtext'" RELOAD'
  158.     end
  159.     else do
  160.         'Get ACTIVEPORT VAR' port
  161.         tempfile="t:autosearch."Right(port, Length(port)-Pos('.', port))".html"
  162.  
  163.         ct=1
  164.         html="<html><head><title>Search results for ""args""</title></head><body>"
  165.  
  166.         'GetCFG FRAMES VAR' frames
  167.         If frames then do
  168.             html=html||'<div align="center" id="'top'">'
  169.             server_html=""
  170.             head_html=""
  171.  
  172.             do while s.ct.name ~== "S."ct".NAME"
  173.                 If (s.ct.use == 1) then do
  174.                     head_html=head_html||'<a href="#'ct'">'s.ct.name' results</a>   '
  175.                     server_html=server_html||'<p><iframe src="'s.ct.url||searchtext'" width="95%" height="83%" id="'ct'"></iframe><p><a href="'#top'">Back to top</a>'
  176.                 end
  177.                 ct=ct+1
  178.             end
  179.             html=html||head_html||server_html||'<p>'head_html'</div></body></html>'
  180.         end
  181.         else do
  182.             head_html=""
  183.             server_html="<h1>Search ""args"" on:</h1><p><ul>"
  184.  
  185.             do while s.ct.name ~== "S."ct".NAME"
  186.                 If (s.ct.use == 1) then do
  187.                     server_html=server_html||'<li><a href="'s.ct.url||searchtext'">'s.ct.name'</a>'
  188.                 end
  189.                 ct=ct+1
  190.             end
  191.             html=html||head_html||server_html||head_html'</ul></body></html>'
  192.         end
  193.  
  194.         Call SendToAWeb(tempfile)
  195.     end
  196.     return
  197.  
  198.  
  199. findpath:
  200.     procedure
  201.  
  202.     parse ARG pathf
  203.     dir_pos = Max(lastpos('/', pathf), lastpos(':', pathf))
  204.     If dir_pos > 0    then
  205.         return(left(pathf,dir_pos))
  206.     else
  207.         return('')
  208.